import requests
import parsel

for page in range(1,10):
    print(f'=======第{page}页=======')
    url = f'https://ibaotu.com/shipin/7-0-0-0-0-{page}.html'
    headers = {
        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.54 Safari/537.36'
    }

    response = requests.get(url=url, headers=headers)
    html = response.text
    #print(html)


    selector = parsel.Selector(html)
    lis = selector.xpath('//ul[@class="clearfix"]/li')  #所以li标签

    for li in lis:
        video_title = li.xpath('./@pr-data-title').get()
        video_url = li.xpath('.//video/@src').get()
        #print(video_title,video_url)

        video_url = 'https:' + video_url

        video_data = requests.get(url=video_url, headers=headers).content

        with open('video\\' + video_title + '.mp4', mode='wb') as f:
            f.write(video_data)
            print('保存完成', video_title)